package tmt.usercenter.web.controller.admin;


import com.tmt.datatable.editor.EditorModel;
import com.tmt.datatable.editor.EditorValid;
import com.tmt.datatable.ext.controller.DataTableController;
import com.tmt.datatable.ext.controller.SelectOptions;
import com.tmt.datatable.ext.controller.TablePage;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tmt.usercenter.web.common.Const;
import tmt.usercenter.web.domain.UserInfoConfig;
import tmt.usercenter.web.service.UserInfoConfigService;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.concurrent.ExecutionException;

@Getter
@Setter
@Controller
@RequestMapping(Const.ADMIN_PATH + "/userinfoconfig")
@TablePage(Const.ADMIN_PATH + "/userinfoconfig/userinfoconfig-index")
public class UserInfoConfigController extends DataTableController<UserInfoConfig, Long> {

    @Autowired
    private UserInfoConfigService uiConfigService;

    @Override
    public EditorModel<UserInfoConfig> doTableAction(@Valid @EditorValid EditorModel<UserInfoConfig> editor)
            throws ExecutionException, InterruptedException {
        return super.doTableAction(editor);
    }

    @ResponseBody
    @RequestMapping("/regfields/select2")
    public SelectOptions queryUserRegisterFieldsForSelect2(HttpServletRequest request, @RequestParam(value = "search", required = false) String search,
                                                           @RequestParam(value = "page", defaultValue = "0") Integer pageIndex,
                                                           @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return uiConfigService.getUserRegisterFieldsForSelect2();
    }

}
